package com.leetcode.tree;

public class Leetcode108 {
    public TreeNode sortedArrayToBST(int[] nums) {
        if (nums.length == 0) {
            return null;
        }
        return arrayToBST(0, nums.length - 1, nums);
    }

    private TreeNode arrayToBST(int left, int right, int[] nums) {
        if (left > right) {
            return null;
        }
        int mid = (right + left ) / 2;
        TreeNode node = new TreeNode(nums[mid]);
        node.left = arrayToBST(left, mid -1, nums);
        node.right = arrayToBST(mid + 1, right, nums);
        return node;
    }



    public static void main(String[] args) {
        int[] arr = {-10,-3,0,5,9};
        Leetcode108 leet = new Leetcode108();
        leet.sortedArrayToBST(arr);
    }
}
